
$().ready(function(){
    //获取banner
    function init(){
        getBanner();
        getNews();
        insertLink();
    }
    init();

    //弹出联系我们
    var cilentHeight = document.body.offsetHeight;
    $('#fixed-body').css('height',cilentHeight+'px');
    $('.group-name').text(global.titleName);
    $('.group-address').text(global.address);
    $('.group-telephone').text(global.telePhone);
    var closeBtn = document.getElementById('closeNav');
    var openBtn = document.getElementById('openNav');
    var fixedBody = document.getElementById('fixed-body');
    openBtn.addEventListener('click',function(){
        fixedBody.style.display = 'block';
        setTimeout(function(){
            fixedBody.style.opacity = 1;
        },100)
    })
    closeBtn.addEventListener('click',function(){
        fixedBody.style.opacity = 0;
        setTimeout(function(){
            fixedBody.style.display = 'none';
        },100)
    })
})
//滚动播报function
function AutoScroll(obj) {
    $(obj).find("ul:first").animate({
            marginTop: "-45px"
        },
        1000
        ,
        function() {
            $(this).css({
                marginTop: "0px"
            }).find("li:first").appendTo(this);
        }
    );
}
//banner
function getBanner(){
    sendAjaxAsync(global.url + '/Api/New/get_banner',function(res){
        console.log(res);
        let html = '';
        for(let i in res){
            html += `
                <div class="swiper-slide">
                    <a href="${res[i].url}">
                        <img src="${res[i].banner_img}" alt="${res[i].title}">
                    </a>
                </div>
            `
        }
        $('#banner').html(html);
        // console.log($('#banner img').height());
        $('#banner img').get(0).onload = function(){
            console.log($('#banner img'));
            let bannerHeight = $('#banner img').height();
            $('.slider').css('height',bannerHeight);
        }
        let swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            loop:true,
            autoplay: 2500,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev'
        });

    },{
        type:2
    })
}
function getNews(){
    let groupNewsUrl = global.url+"/Api/New/first_jtxw_eight"
    sendAjaxAsync(groupNewsUrl,function (res) {
        console.log(res);
        var html = '';
        for(var i=0;i<res.length;i++){
            html += ` <li>
            <a href="arctical.html?nav=1&item=0&id=${res[i].id}">
            <div class="news-date">${res[i].date}</div>
            <div class="news-title">${res[i].title}</div></a>
            </li>`
        }
        $(".news-list").html(html);
    })
    setInterval('AutoScroll("#news-box")',5000);
}
function insertLink(){
    let html = '';
    for(let i in mainList){
        html += `
            <div class="nav-item-box animated fadeInUp">
                <div class="nav-items">
                    <a href="${mainList[i].link}?nav=${mainList[i].id}">
                        <div class="item-content">
                            <p class="title-cn">${mainList[i].name}</p>
                            <p class="title-en">${mainList[i].en}</p>
                        </div>
                        <img src="img/arrow.png" alt="">
                    </a>
                </div>
            </div>
        `
    }
    $('#nav-item-link').html(html);
}
